<%-- 
    Document   : listFiles
    Created on : 11 juin 2014, 15:12:57
    Author     : noelladana
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="com.cassiopae.entity.User"%>
<%@page import="com.cassiopae.entity.Profile"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Users List</title>

<!-- Core CSS - Include with every page -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="font-awesome/css/font-awesome.css" rel="stylesheet">

<!-- Page-Level Plugin CSS - Tables -->
<link href="css/plugins/dataTables/dataTables.bootstrap.css"
	rel="stylesheet">

<!-- SB Admin CSS - Include with every page -->
<link href="css/sb-admin.css" rel="stylesheet">



</head>

<body>
	<script type="text/javascript">
		ObjSelec = null;
		function SelectLigne(obj)
		{
			var idLigne=obj.id;
			obj.className="selection";
			if (ObjSelec!=null)
			{
				ObjSelec.className = "defaut";
				ObjSelec = obj;
			}
			else
			{
				ObjSelec = obj;
			}
		}
		function verif_bouton()
		{
			btn1=document.form1.getElementById("creer") ; 
			btn1.disabled=false;
		}

		function deleteUser(userID)
		{
     		document.getElementById("deleteUserID").value = userID;
		}

		function onSchemaClick(){
			var nombreDeSchema = document.getElementById("lengthSchema").value;
			if( document.getElementById("allSchemaID").checked ){
				for( var i=0;i< nombreDeSchema;i++){
					var nom = "schema"+i;
					document.getElementById(nom).checked = true;
				}
					
			}else{
				for( var i=0;i< nombreDeSchema;i++){
					var nom = "schema"+i;
					document.getElementById(nom).checked = false; 
				}
			}
		}
		
		function move(tbFrom, tbTo) {
			var arrFrom = new Array();
			var arrTo = new Array();
			var arrLU = new Array();
			var i;
			for (i = 0; i < tbTo.options.length; i++) {
				arrLU[tbTo.options[i].text] = tbTo.options[i].value;
				arrTo[i] = tbTo.options[i].text;
			}
			var fLength = 0;
			var tLength = arrTo.length;
			for (i = 0; i < tbFrom.options.length; i++) {
				arrLU[tbFrom.options[i].text] = tbFrom.options[i].value;
				if (tbFrom.options[i].selected && tbFrom.options[i].value != "") {
					arrTo[tLength] = tbFrom.options[i].text;
					tLength++;
				} else {
					arrFrom[fLength] = tbFrom.options[i].text;
					fLength++;
				}
			}

			tbFrom.length = 0;
			tbTo.length = 0;
			var ii;

			for (ii = 0; ii < arrFrom.length; ii++) {
				var no = new Option();
				no.value = arrLU[arrFrom[ii]];
				no.text = arrFrom[ii];
				tbFrom[ii] = no;
			}

			for (ii = 0; ii < arrTo.length; ii++) {
				var no = new Option();
				no.value = arrLU[arrTo[ii]];
				no.text = arrTo[ii];
				tbTo[ii] = no;
			}
		}
		function selectAllOptions(obj) {
		    for (var i=0; i<obj.options.length; i++) {
		        obj.options[i].selected = true;
		    }
		 } 
	</script>
	<div id="wrapper">

		<nav class="navbar navbar-default navbar-fixed-top" role="navigation"
			style="margin-bottom: 0">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle" data-toggle="collapse"
					data-target=".sidebar-collapse">
					<span class="sr-only">Toggle navigation</span> <span
						class="icon-bar"></span> <span class="icon-bar"></span> <span
						class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="index.jsp">Welcome to CASSIOPAE
					DUMP</a>
			</div>

			<!-- /.dropdown -->
			<ul class="nav navbar-top-links navbar-right">
				<li class="dropdown"></li>
				<!-- /.dropdown -->
				
				<li class="dropdown"><a class="dropdown-toggle"
					data-toggle="dropdown" href="#"> <i class="fa fa-user fa-fw"></i>
						<i class="fa fa-caret-down"></i>
				</a>
					<ul class="dropdown-menu dropdown-user">
						<li><a href="#"><i class="fa fa-user fa-fw"></i>
								<% User user = (User) request.getSession().getAttribute("user"); %>
								<label><%=user.getPrenom()+" "%><%=user.getNom() %></label>
							</a></li>
						<li class="divider"></li>
						<li><a href="DeconnexionServlet"><i
								class="fa fa-sign-out fa-fw"></i> Sign up</a></li>
					</ul> <!-- /.dropdown-user --></li>
				<!-- /.dropdown -->
			</ul>
			<!-- /.navbar-top-links -->

			<div class="navbar-default navbar-static-side" role="navigation">
				<div class="sidebar-collapse">
					<ul class="nav" id="side-menu">
						
						<li><a href="listProfile.jsp"><i class="fa fa-home fa-fw"></i>
								Home</a></li>
					</ul>
					<!-- /#side-menu -->
				</div>
				<!-- /.sidebar-collapse -->
			</div>
			<!-- /.navbar-static-side -->
		</nav>

		<div id="page-wrapper">
			<div class="row">
				<div class="col-lg-12">
					<h4 class="page-header">Users management</h4>
				</div>
				<!-- /.col-lg-12 -->
			</div>
			<!-- /.row -->
			<div class="row">
				<div class="col-lg-12">
					<a style="text-decoration: none;" href="#" data-toggle="modal"
							data-target="#myRegisterFile" id="creer"
							onload="verif_bouton();"> <i class="fa fa-user fa-fw"></i>Create
							an account
						</a><span class="clearfix"></span>				
					<h5 class="divider"></h5>
				</div>
				<!-- /.col-lg-12 -->
			</div>
			<!-- /.row -->
			<div class="row">
				<div class="col-lg-12">
					<div class="panel panel-default">
						<div class="panel-heading">List of users</div>
						<!-- /.panel-heading -->
						<div class="panel-body">
							<div>
								<table class="table" id="dataTables-example">
									<thead>
										<tr>
											<th>FirstName</th>
											<th>LastName</th>
											<th>Login</th>
											<th>Permission</th>
											<th>Status</th>
											<th>Delete</th>
<!-- 											<th>Update</th> -->
										</tr>
									</thead>
									<tbody>
										<%
                                            List<User> users = ( ArrayList) request.getAttribute("LISTUSER");
                                            int i = 0;
                                            for(User u : users){
                                        %>
										<tr class="defaut" id="ligne<%=i++ %>"
											onclick="SelectLigne(this);verif_bouton();">
											<td><%=u.getNom() %></td>
											<td><%=u.getPrenom() %></td>
											<td><%=u.getLogin() %></td>
											<td><a href="ListUserServlet?userEmail=<%=u.getEmail()%>&activer=<%=!u.getActivateOrNot()%>"><%= u.getActivateOrNot() ?  "d&eacute;sactiver" : "activer" %></a></td>
											<td>
												<%
													if (u.getActivateOrNot()) {
												%> <img src="image/Unlock.png" /> <%
 													} else {
												%> <img src="image/Lock.png" /> <%
 													}
												%>
											</td>
											<td>
												<a style="text-decoration: none;" 
												data-toggle="modal" data-target="#myDeleteUser" name="creer" onclick="deleteUser('<%=u.getEmail() %>');"
												id="creer"><img alt="" src="image/delete.png" height="80%"
														width="40%" />
												</a></td>
<!-- 											<td><a style="text-decoration: none;" href="#" -->
<!-- 												data-toggle="modal" data-target="#myUpdateFile" id="creer" -->
<!-- 												onload="verif_bouton();">Update -->
<!-- 											</a><span class="clearfix"></span></td> -->
										</tr>

										<%
                                                }
                                        %>
									</tbody>
								</table>
							</div>

						</div>
						<!-- /.panel-body -->
					</div>
					<!-- /.panel -->
				</div>
				<!-- /.col-lg-12 -->
			</div>



		</div>
		<!-- /#page-wrapper -->

	</div>
	<!-- /#wrapper -->

	<!-- Core Scripts - Include with every page -->
	<script src="js/jquery-1.10.2.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script src="js/plugins/metisMenu/jquery.metisMenu.js"></script>

	<!-- Page-Level Plugin Scripts - Tables -->
	<script src="js/plugins/dataTables/jquery.dataTables.js"></script>
	<script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>

	<!-- SB Admin Scripts - Include with every page -->
	<script src="js/sb-admin.js"></script>

	<!-- Page-Level Demo Scripts - Tables - Use for reference -->
	<script>
    $(document).ready(function() {
        $('#dataTables-example').dataTable();
    });
    </script>
<!-- create an account début -->
	<div class="modal fade" id="myRegisterFile" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">Create user</h4>
				</div>
				<form role="form" action="RegisterServlet" method="post">
									<div class="modal-body">
 
										<!-- <input class="form-control" type="password" name="confirmpassword" placeholder="Confirm password" onclick="validatePassword();" autofocus required>
										<input class="form-control" type="text" name="prenom" placeholder="First Name" required><br/>
										<input class="form-control" type="text" name="nom" placeholder="Last Name" autofocus required><br/> -->
										<input class="form-control" type="email" name="email" placeholder="Email" autofocus required><br/>
										<input class="form-control" type="password" name="password" placeholder="Password" autofocus required><br/>
										<hr/>
										<label>Schemas</label>
										<table><tr><td>
										<select multiple size="10" name="FromLB" style="width:150px;" ondblclick="move(this.form.FromLB,this.form.ToLB)" >
										<%
											String schemas[] = ( String[]) request.getSession().getAttribute("LISTSCHEMA");
											for( String schema : schemas){
											
										%>
										<option value="<%=schema%>"><%=schema%></option>
										<%
											}
										%>
										</select>
										</td>
										
										<td align="center" valign="middle">
										<input type="button" onClick="move(this.form.FromLB,this.form.ToLB)" 
										value="->"><br />
										<input type="button" onClick="move(this.form.ToLB,this.form.FromLB)" 
										value="<-">
										</td>
										<td>
										<select required multiple size="10" name="ToLB" style="width:150px;" ondblclick="move(this.form.ToLB,this.form.FromLB)">
										</select>
										</td></tr></table>

									</div>
									<div class="modal-footer">
										<button type="button" class="btn btn-default"
											data-dismiss="modal">Close</button>
										<input class="btn btn-success" type="submit" onclick="selectAllOptions(ToLB);"
											name="creerFolder" Value="create an account" />
									</div>
								</form>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
<!-- create an account fin -->

<!-- update an account début -->
	<div class="modal fade" id="myUpdateFile" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">Update user</h4>
				</div>
				<form role="form" action="ActionServlet?action=modifierUser" method="get">
					<div class="modal-body">

						<input class="form-control" type="text" name="prenom"
							placeholder="First Name" required><br /> <input
							class="form-control" type="text" name="nom"
							placeholder="Last Name" autofocus required><br /> <input
							class="form-control" type="text" name="login" placeholder="Login"
							autofocus required><br />
						
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
						<input class="btn btn-success" type="submit" name="creerFolder"
							Value="Update an account" />
					</div>
				</form>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- update an account fin -->
	
	<!-- Fenetre de suppression DEBUT -->
	<div class="modal fade" id="myDeleteUser" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">Delete</h4>
				</div>
				<form role="form" action="ActionServlet" method="get">
					<div class="modal-body">

						<label>Are you sure you want to remove this user ?</label>
					
						<input class="form-control" type="hidden" name="deleteUserID"
							id="deleteUserID">
						<input class="form-control" type="hidden" name="action" value="supprimerUser">
					</div>	
					<div class="modal-footer">
						<input class="btn btn-success" type="submit" name="delete"
							Value="Yes" />
						<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
						

					</div>
				</form>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>

	<!--Fenetre de suppression FIN -->

</body>


</html>
